package top.btcmarket.TestProject;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.LocalDateTime;

import com.alibaba.druid.util.StringUtils;

public class JodaTime {

	/*public static Date getUTCTime(){
	DateTime nowLocal1 = new DateTime();
	LocalDateTime nowUTC1 = nowLocal1.withZone(DateTimeZone.UTC).toLocalDateTime();
	 Date dUTC = nowUTC1.toDate();
	 
	 return dUTC ;
}

public static String getUTCTimeStr(){
	DateTime nowLocal1 = new DateTime();
	LocalDateTime nowUTC1 = nowLocal1.withZone(DateTimeZone.UTC).toLocalDateTime();
	 
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
	 return sdf.format(nowUTC1.toDate());
}*/
	
	public static void main(String[] args) {
		
		
		/*System.out.println(getUTCTimeStr());
		System.out.println(getUTCTime());*/
		
		
		DateTime dt = new DateTime();
	    DateTimeZone tz = DateTimeZone.getDefault();
	    LocalDateTime nowLocal = new LocalDateTime();
	    DateTime nowUTC = nowLocal.toDateTime(DateTimeZone.UTC);

	    Date d1 = nowLocal.toDate();
	    Date d2 = nowUTC.toDate();

	    System.out.println("tz: " + tz.toString());
	    System.out.println("local: " + d1.toString());
	    System.out.println("utc: " + d2.toString());
	    
	    
	    DateTimeZone tz1 = DateTimeZone.getDefault();
	    DateTime nowLocal1 = new DateTime();
	    LocalDateTime nowUTC1 = nowLocal1.withZone(DateTimeZone.UTC).toLocalDateTime();
	    DateTime nowUTC2 = nowLocal1.withZone(DateTimeZone.UTC);

	    Date dLocal = nowLocal1.toDate();
	    Date dUTC = nowUTC1.toDate();
	    Date dUTC2 = nowUTC2.toDate();

	    System.out.println("------------------------");
	    System.out.println("tz    : " + tz1.toString());
	    System.out.println("local : " + nowLocal1 +     " | " + dLocal.toString());
	    System.out.println("utc   : " + nowUTC1 +       " | " + dUTC.toString()); // <= WORKING SOLUTION
	    System.out.println("utc2  : " + nowUTC2 +      " | " + dUTC2.toString());
	    //-----------------------------------------------------------------------------------
	    
	    DateTime utcTtest = DateTime.now(DateTimeZone.UTC);
	    System.out.println("utc3  : "+utcTtest);
	    System.out.println("utc31  : "+utcTtest.toString());
	    System.out.println("utc4  : "+utcTtest.toDate());
	    
	    //1525847542
	    
	    
	    Date date = new Date(1525847542*1000);
//	    DateTime ddt = new DateTime(date);
	    
//	    String date = new SimpleDateFormat(formats, Locale.CHINA).format(new Date(timestamp));
	    
//	    System.out.println(" ddt  "+ddt.toString());
//	    String time = TimeStamp2Date("1525847542","");
	    String time = TimeStamp2Date("1530772350","");
	    System.out.println(" time : "+time);
	    System.out.println("utc:"+DateFormatUtils.formatUTC(date, "yyyy-MM-dd HH:mm:ss"));
	    
	    // 1527186709000
	    String time1 = TimeStamp2Date("1532934592","");
	    System.out.println(" time11-------- : "+time1);
	    System.out.println("utc:---"+DateFormatUtils.formatUTC(date, "yyyy-MM-dd HH:mm:ss"));
	    System.out.println("utc:"+DateFormatUtils.format(date, "yyyy-MM-dd HH:mm:ss"));
	    
	    
	    
	    System.out.println("ddddddddddd"+Long.MAX_VALUE);
	    
	    //1532905792000
	    Date daterrr = new Date(1532934592000L);
	    System.out.println("utc----dddd---format---:"+DateFormatUtils.format(daterrr, "yyyy-MM-dd HH:mm:ss"));
	    
	    System.out.println("utc----dddd---formatUTC---:"+DateFormatUtils.formatUTC(daterrr, "yyyy-MM-dd HH:mm:ss"));
	    Date date11 = new Date(1532934555490L);
	    System.out.println("utc----create------:"+DateFormatUtils.format(date11, "yyyy-MM-dd HH:mm:ss"));
	    Date date12= new Date(1532928851423L);
	    System.out.println("utc----update------:"+DateFormatUtils.format(date12, "yyyy-MM-dd HH:mm:ss"));
	    Date date13 = new Date(1532905792000L);
	    System.out.println("utc----trx------:"+DateFormatUtils.format(date13, "yyyy-MM-dd HH:mm:ss"));
	    
	    //System.out.println("utc--utc--trx------:"+DateFormatUtils.formatUTC(date13, "yyyy-MM-dd HH:mm:ss"));
	    
	    
	    SimpleDateFormat sdf11 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	    String format = sdf11.format("2018-05-22 07:31:30.0");
	    System.out.println(format);
	
	    
	    
	}
	
	public static String TimeStamp2Date(String timestampString, String formats) {
        if (StringUtils.isEmpty(formats)){
        	formats = "yyyy-MM-dd HH:mm:ss";
        }
            
        Long timestamp = Long.parseLong(timestampString) * 1000;
       System.out.println("data --- "+ new Date(timestamp));
        String date = new SimpleDateFormat(formats).format(new Date(timestamp));
        return date;
    }
	
	 /**
     * 日期格式字符串转换成时间戳
     *
     * @param dateStr 字符串日期
     * @param format   如：yyyy-MM-dd HH:mm:ss
     *
     * @return
     */
    public static String Date2TimeStamp(String dateStr, String format) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(format);
            return String.valueOf(sdf.parse(dateStr).getTime() / 1000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
    
}
